//
//  AboutViewController.m
//  ToYourHeartNews
//
//  Created by XJing on 16/2/27.
//  Copyright © 2016年 www.lanou3g.com 蓝鸥. All rights reserved.
//

#import "AboutViewController.h"
#import <MessageUI/MessageUI.h>
@interface AboutViewController ()<MFMessageComposeViewControllerDelegate>

@end

@implementation AboutViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //介绍内容
    UILabel *contentLable = [[UILabel alloc]initWithFrame:CGRectMake(10, self.view.frame.size.height / 5, self.view.frame.size.width - 20, self.view.frame.size.height / 5)];
    contentLable.numberOfLines = 0;
    contentLable.text = @"口袋新闻是包含新闻,视频,搞笑动图,专题话题的一款应有尽有的新闻App, <<口袋新闻>>在手,全球新闻装进口袋";
    contentLable.font = [UIFont systemFontOfSize:19];
    contentLable.layer.cornerRadius = 5;
    contentLable.clipsToBounds = YES;
    contentLable.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:contentLable];
    [contentLable release];
    //发短信按钮
    UIButton *phone = [UIButton buttonWithType:UIButtonTypeCustom];
    phone.frame = CGRectMake(self.view.frame.size.width / 5, self.view.frame.size.height / 10 * 6, self.view.frame.size.width / 5 * 3, 40);
    [phone addTarget:self action:@selector(phoneAction) forControlEvents:UIControlEventTouchUpInside];
    phone.layer.cornerRadius = 10;
    phone.clipsToBounds = YES;
    [phone setBackgroundColor:[UIColor redColor]];
    [phone setTitle:@"推荐给好友" forState:UIControlStateNormal];
    [self.view addSubview:phone];
}
#pragma mark - 发短信
-(void)phoneAction
{
    
    [self showMessageView:[NSArray arrayWithObjects:@"", nil] title:@"test" body:@"口袋新闻真的是一款不错的App,快去下载吧!"];
}
#pragma mark - 实现代理方法
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    [self dismissViewControllerAnimated:YES completion:nil];
    switch (result) {
        case MessageComposeResultSent:
            //信息传送成功
            NSLog(@"发送成功");
            
            //弹窗
            UIAlertController *promptAlert = [UIAlertController alertControllerWithTitle:@"提示" message:@"推荐成功" preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                //
                NSLog(@"确定");
            }];
            [promptAlert addAction:cancleAction];
            [self presentViewController:promptAlert animated:YES completion:^{
                
            }];
            break;
        case MessageComposeResultFailed:
            //信息传送失败
            
            break;
        case MessageComposeResultCancelled:
            //信息被用户取消传送
            
            break;
        default:
            break;
    }

}
#pragma mark - 发送短信
-(void)showMessageView:(NSArray *)phones title:(NSString *)title body:(NSString *)body
{
    if( [MFMessageComposeViewController canSendText] )
    {
        MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init];
        controller.recipients = phones;
        controller.navigationBar.tintColor = [UIColor redColor];
        controller.body = body;
        controller.messageComposeDelegate = self;
        [self presentViewController:controller animated:YES completion:nil];
        [[[[controller viewControllers] lastObject] navigationItem] setTitle:title];//修改短信界面标题
        [controller release];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示信息"
                                                        message:@"该设备不支持短信功能"
                                                       delegate:nil
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
